import 'package:distribution_mall_flutter/assets.dart';
import 'package:distribution_mall_flutter/constant/cf_constant.dart';
import 'package:distribution_mall_flutter/entity/address/address_entity.dart';
import 'package:distribution_mall_flutter/generated/l10n.dart';
import 'package:distribution_mall_flutter/utils/common_widget.dart';
import 'package:distribution_mall_flutter/utils/utils.dart';
import 'package:distribution_mall_flutter/widgets/radio_list_tile.dart';
import 'package:flutter/material.dart';
import 'package:getwidget/colors/gf_color.dart';
import 'package:getwidget/components/radio/gf_radio.dart';
import 'package:getwidget/types/gf_radio_type.dart';

class EPAddressItem extends StatelessWidget {
  final AddressItem data;
  final Function(bool bol)? defCallback;
  final Function(AddressItem data)? itemCallback;
  final VoidCallback editCallback;
  final VoidCallback delCallback;
  final bool isEditMode;

  const EPAddressItem({
    super.key,
    required this.data,
    required this.isEditMode,
    this.defCallback,
    this.itemCallback,
    required this.editCallback,
    required this.delCallback,
  });

  final TextStyle editTextStyle = const TextStyle(
      color: Color.fromRGBO(134, 141, 150, 1),
      fontSize: 10.9,
      letterSpacing: TextConstant.letterSpacing);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        if (itemCallback is Function) {
          itemCallback!(data);
        }
      },
      behavior: HitTestBehavior.translucent,
      child: Container(
        padding: const EdgeInsets.only(bottom: 5),
        decoration: const BoxDecoration(
            border: Border(bottom: BorderSide(color: ColorConstant.grey233))),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Container(
              margin: const EdgeInsets.only(top: 16),
              child: Row(
                children: [
                  Expanded(
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Padding(
                          padding: const EdgeInsets.only(bottom: 8),
                          child: Row(
                            children: [
                              Text(data.recipientName ?? '',
                                  style: const TextStyle(
                                      color: Color(0xFF515151),
                                      fontWeight: FontWeight.bold,
                                      fontSize: 12,
                                      letterSpacing:
                                          TextConstant.letterSpacing)),
                              Container(
                                margin: const EdgeInsets.only(left: 8),
                                child: Text(data.phone ?? '',
                                    style: const TextStyle(
                                        color: Color(0xFF515151),
                                        fontWeight: FontWeight.bold,
                                        fontSize: 12,
                                        letterSpacing:
                                            TextConstant.letterSpacing)),
                              ),
                            ],
                          ),
                        ),
                        Text(
                          Utils.formatAddress(data),
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                          style: const TextStyle(
                              color: Color(0xFF000000),
                              fontSize: 14,
                              letterSpacing: TextConstant.letterSpacing),
                        )
                      ],
                    ),
                  ),
                  const SizedBox(
                    width: 20,
                  ),
                  GestureDetector(
                    onTap: () {
                      editCallback();
                    },
                    behavior: HitTestBehavior.opaque,
                    child: Padding(
                      padding:
                          const EdgeInsets.only(left: 10, top: 5, bottom: 5),
                      child: Image.asset(
                        Assets.assets_icons_address_edit_png,
                        width: 16,
                      ),
                    ),
                  ),
                ],
              ),
            ),
            Container(
              margin: const EdgeInsets.only(top: 8),
              child: Row(
                children: [
                  Text(data.zip ?? '',
                      style: const TextStyle(
                          color: Color(0xFF515151), fontSize: 12)),
                  const SizedBox(
                    width: 5,
                  ),
                  Text(data.detailInfo ?? '',
                      style: const TextStyle(
                        color: Color(0xFF515151),
                        fontSize: 12,
                      )),
                  if (data.isDef == true)
                    Container(
                      margin: const EdgeInsets.only(left: 10),
                      decoration: const BoxDecoration(
                          color: Color(0x3B5483BF),
                          borderRadius: BorderRadius.all(Radius.circular(2))),
                      padding: const EdgeInsets.all(2),
                      child: const Text(
                        'Default',
                        style:
                            TextStyle(fontSize: 10, color: Color(0xFF5483BF)),
                      ),
                    )
                ],
              ),
            ),
            if (isEditMode)
              Container(
                margin: const EdgeInsets.only(top: 15),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    EPRadioListTile(
                        defaultFontSize: 10.9,
                        isSelect: data.isDef ?? false,
                        onChanged: defCallback),
                    CommonBtnWidget.textBtn(
                        onPressed: () {
                          delCallback();
                        },
                        width: 40,
                        height: 30,
                        text: S.current.delete,
                        textStyle: editTextStyle)
                  ],
                ),
              ),
          ],
        ),
      ),
    );
  }
}
